"use strict";
/* Controllers */
app.controller("ownerListController", ['$scope', '$location', '$rootScope', '$routeParams', 'ownerListService', function ($scope, $location, $rootScope, $routeParams, ownerListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.appID = $routeParams.appID; //  获取应用模块的名称

    vm.p.contractCode = "";
    vm.p.startTime = getNowFormatDate(-30);
    vm.p.endTime =  getNowFormatDate(-1);

    var errorFn = function (result) {
        alert(result);
    };

    $scope.searchOwner = function (t) {
        var vm = $scope.vm;
        switch(t) {
            case 1:
                vm.p.startTime = 0;
                vm.p.endTime = 0;
                break;
            case 2:
                vm.p.subBillNo = "";
                break;
            default:
                break;
        }
        $scope.listOwner();
    };

    $scope.listOwner = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {appID: vm.p.appID};
        if (vm.p.contractCode !== "" && vm.p.contractCode !== 0) {
            params.contractCode = vm.p.contractCode;
        }
        if (vm.p.startTime !== "" && vm.p.startTime !== 0) {
            params.startTime = vm.p.startTime;
        }
        if (vm.p.endTime !== "" && vm.p.endTime !== 0) {
            params.endTime = vm.p.endTime;
        }
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        ownerListService.listOwner(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $resultTable.bootstrapTable('hideColumn', 'action');
        $scope.listOwner();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('ownerListService', ['ajaxService', function (ajaxService) {

    this.listOwner = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/tfz_order/tfz_order_list.do", successFunction, errorFunction);
    };
}]);

